package com.etc.service.impl;

import java.util.List;

import com.etc.dao.AdminDao;
import com.etc.dao.impl.AdminDaoImpl;
import com.etc.entity.Admin;
import com.etc.entity.Business;
import com.etc.entity.Customer;
import com.etc.entity.Games;
import com.etc.entity.PageInfo;
import com.etc.service.AdminService;



public class AdminServiceImpl implements AdminService {
	private AdminDao adminDao = new AdminDaoImpl();

	@Override
	public PageInfo<Customer> getCustomerListByPage(String nickNameKeyWord, int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		StringBuffer sb = new StringBuffer();
		if(nickNameKeyWord != null && !"".equals(nickNameKeyWord)) {
			sb.append("%").append(nickNameKeyWord).append("%");
			nickNameKeyWord = sb.toString();
		}
		
		int total = adminDao.countCustomerByCondition(nickNameKeyWord);
		
		List<Customer> data = adminDao.getPageCustomerByCondition(nickNameKeyWord, pageNum, pageSize);
		
		PageInfo<Customer> pageInfo = new PageInfo<Customer>(data, pageNum, pageSize, total);
		return pageInfo;
	}
	@Override
	public Boolean deleteCustomerById(int CustomerId) {
		// TODO Auto-generated method stub
		return adminDao.deleteCustomer(CustomerId) > 0;
	}
	@Override
	public Boolean addCustomer(Customer customer) {
		// TODO Auto-generated method stub
		return adminDao.addCustomer(customer) > 0;
	}
	@Override
	public Boolean updateCustomer(Customer customer) {
		// TODO Auto-generated method stub
		return adminDao.updateById(customer) > 0;
	}
	@Override
	public Customer getCustomerById(int customerId) {
		// TODO Auto-generated method stub
		return adminDao.findById(customerId);
	}
	@Override
	public PageInfo<Business> getBusinessListByPage(String nickNameKeyWord, int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		StringBuffer sb = new StringBuffer();
		if(nickNameKeyWord != null && !"".equals(nickNameKeyWord)) {
			sb.append("%").append(nickNameKeyWord).append("%");
			nickNameKeyWord = sb.toString();
		}
		
		int total = adminDao.countBusinessByCondition(nickNameKeyWord);
		
		List<Business> data = adminDao.getPageBusinessByCondition(nickNameKeyWord, pageNum, pageSize);
		
		PageInfo<Business> pageInfo = new PageInfo<Business>(data, pageNum, pageSize, total);
		return pageInfo;
	}
	@Override
	public Boolean deleteBusinessById(int businessId) {
		// TODO Auto-generated method stub
		return adminDao.deleteBusiness(businessId) > 0;
	}
	@Override
	public Boolean addBusiness(Business business) {
		// TODO Auto-generated method stub
		return adminDao.addBusiness(business) > 0;
	}
	@Override
	public Boolean updateBusiness(Business business) {
		// TODO Auto-generated method stub
		return adminDao.updateBusinessById(business) > 0;
	}
	@Override
	public Business getBusinessById(int businessId) {
		// TODO Auto-generated method stub
		return adminDao.findBusinessById(businessId);
	}
	@Override
	public Boolean updateBusinessStatus(int status, int businessId) {
		// TODO Auto-generated method stub
		return adminDao.updateBusinessStatus(businessId, status) > 0;
	}
	@Override
	public PageInfo<Games> getGamesListByPage(String nickNameKeyWord, int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		StringBuffer sb = new StringBuffer();
		if(nickNameKeyWord != null && !"".equals(nickNameKeyWord)) {
			sb.append("%").append(nickNameKeyWord).append("%");
			nickNameKeyWord = sb.toString();
		}
		
		int total = adminDao.countGamesByCondition(nickNameKeyWord);
		
		List<Games> data = adminDao.getPageGamesListByCondition(nickNameKeyWord, pageNum, pageSize);
		
		PageInfo<Games> pageInfo = new PageInfo<Games>(data, pageNum, pageSize, total);
		return pageInfo;
	}
	@Override
	public Boolean updateGamesStatus(int status, int gamesId) {
		// TODO Auto-generated method stub
		return adminDao.updateGameStatus(gamesId, status) > 0;
	}
	@Override
	public List<Customer> getCustomersList() {
		// TODO Auto-generated method stub
		return adminDao.getCustomersList();
	}
	@Override
	public List<Business> getBusinesssList() {
		// TODO Auto-generated method stub
		return adminDao.getBusinesssList();
	}

}
